# -*- coding:utf-8 -*-
import time

from TestBase.browser_action import Base
from TestBase.webdriver_package import *


class HomePage(Base):

    def __init__(self, case_instance):
        super(HomePage, self).__init__(case_instance, csv_file="home_page.csv")

    def search_ticket(self):
        # 截屏，断言内容是否存在（ 当前页面 ）
        self.screenshot(img_no=1)
        self.assert_content(content=self.data("assert_home_key"), error_msg="首页跳转失败")

        # 点击'火车票'tab
        self.train_tab().click()
        time.sleep(2)

        # 输入'出发城市'
        self.from_city().clear()
        self.from_city().send_keys(self.data("from"))
        self.keyboard_action(key_action=Keys.TAB)
        time.sleep(2)

        # 输入'旅行时间'
        self.js_update_value(ele=self.travel_date(), value=self.data("date"))
        self.keyboard_action(key_action=Keys.TAB)
        time.sleep(2)

        # 输入'到达城市'
        self.to_city().clear()
        self.to_city().send_keys(self.data("to"))
        self.keyboard_action(key_action=Keys.TAB)
        time.sleep(2)

        # 单击'开始搜索'按钮
        self.screenshot(img_no=2)
        self.search_btn().click()
        time.sleep(2)

        # 截屏，断言内容是否存在（ 跳转页面 ）
        self.screenshot(img_no=3)
        self.assert_content(content=self.data("assert_ticket_key"), error_msg="车票信息页跳转失败")
        time.sleep(2)